﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Paas.Pioneer.Admin.Core.Application.Contracts.Personnel.Employee;
using Paas.Pioneer.Admin.Core.Application.Contracts.Personnel.Employee.Dto;
using Paas.Pioneer.Admin.Core.Application.Contracts.Personnel.Employee.Dto.Input;
using Paas.Pioneer.Admin.Core.Application.Contracts.Personnel.Employee.Dto.Output;
using Paas.Pioneer.Domain.Shared.Dto.Input;
using System;
using System.Threading.Tasks;
using Volo.Abp.AspNetCore.Mvc;
using Paas.Pioneer.Domain.Shared.Dto.Output;
using Volo.Abp.Auditing;

namespace Paas.Pioneer.Admin.Core.HttpApi.Controllers.Employee;

/// <summary>
/// 员工管理
/// </summary>
[Route("api/personnel/[controller]")]
[Authorize]
public class EmployeeController : AbpControllerBase
{
    private readonly IEmployeeService _employeeService;

    /// <summary>
    /// 构造函数
    /// </summary>
    /// <param name="employeeService"></param>
    public EmployeeController(IEmployeeService employeeService)
    {
        _employeeService = employeeService;
    }

    /// <summary>
    /// 查询单条员工
    /// </summary>
    /// <param name="id"></param>
    /// <returns></returns>
    [HttpGet("{id}")]
    public async Task<EmployeeGetOutput> Get(Guid id)
    {
        return await _employeeService.GetAsync(id);
    }

    /// <summary>
    /// 查询分页员工
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    [HttpPost("page-list")]

    //[ResponseCache(Duration = 60)]
    public async Task<Page<EmployeeListOutput>> GetPageList([FromBody] PageInput<EmployeeDataOutput> input)
    {
        return await _employeeService.GetPageListAsync(input);
    }

    /// <summary>
    /// 新增员工
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    [HttpPost]
    public async Task Add([FromBody] EmployeeAddInput input)
    {
        await _employeeService.AddAsync(input);
    }

    /// <summary>
    /// 修改员工
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    [HttpPut]
    public async Task Update([FromBody] EmployeeUpdateInput input)
    {
        await _employeeService.UpdateAsync(input);
    }

    /// <summary>
    /// 删除员工
    /// </summary>
    /// <param name="id"></param>
    /// <returns></returns>
    [HttpDelete("{id}")]
    public async Task SoftDelete(Guid id)
    {
        await _employeeService.DeleteAsync(id);
    }

    /// <summary>
    /// 批量删除员工
    /// </summary>
    /// <param name="ids"></param>
    /// <returns></returns>
    [HttpDelete("ids")]
    public async Task BatchSoftDelete([FromBody] Guid[] ids)
    {
        await _employeeService.BatchSoftDeleteAsync(ids);
    }
}